import { put, delay, take, takeLatest } from 'redux-saga/effects'
import { actionTypes, increase } from '../action/counter'

let isStop = false
function* autoIncrease() {
    isStop = false
    while (true) {
        yield delay(2000)
        if (isStop) break
        yield put(increase())
    }
}

function stopAutoIncrease() {
    isStop = true
}

export default function* () {
    yield takeLatest(actionTypes.stopAutoIncrease, stopAutoIncrease)
    yield takeLatest(actionTypes.autoIncrease, autoIncrease)
}